package com.tanhua.sso.controller;

import com.tanhua.sso.service.SmsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("user")
@Slf4j
public class SmsController {
    @Autowired
    private SmsService smsService;

    @PostMapping("login")
    public ResponseEntity<String> sendCheckCode(@RequestBody Map<String, String> param) {
        String result = null;
        try {
            String[] phonenumbers = {param.get("phone")};
            result = smsService.sendSms(phonenumbers);
            if (null == result) {
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            log.error("发送短信验证码失败~  ", e);

        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(result);

    }
}
